﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace project_phoenix.source
{
    public class PlayerHudElement : HudElement
    {
        // Members
        private PlayableEntity mAttachedPlayer;
        private Texture2D mBackground;
        private StatusBar mHealthBar;
        private StatusBar mManaBar;
        private StatusBar mExpBar;
        private int mPlayerIndex;
        private Vector2 mPosition;
        private Texture2D mPicture;

        public PlayerHudElement(PlayableEntity attachee, int playerIndex)
        {
            mAttachedPlayer = attachee;
            mHealthBar = new StatusBar(new Vector2(0.5f, 0.5f), Color.DarkRed, Color.Green, 0.0f);
            mManaBar = new StatusBar(new Vector2(0.5f, 0.5f), Color.DarkBlue, Color.Blue, 0.0f);
            mExpBar = new StatusBar(new Vector2(0.28f, 0.5f), Color.White, Color.Yellow, -90.0f);
            mPlayerIndex = playerIndex;
            mPosition = Vector2.Zero + new Vector2(265*(mPlayerIndex-1), 0);
        }

        public override void Initialize()
        {
            // TODO: Add any initialization
        }

        public override void LoadContent()
        {
            mBackground = GameGlobals.Content.Load<Texture2D>("sprites\\hud\\player_hud");
            mPicture = GameGlobals.Content.Load<Texture2D>(mAttachedPlayer.HudImagePath);
            mHealthBar.LoadContent();
            mManaBar.LoadContent();
            mExpBar.LoadContent();
        }

        // Functions
        // Forced overrides
        public override void Update(GameTime gt)
        {
            mHealthBar.Update(gt, mAttachedPlayer.HealthPercent);
            mManaBar.Update(gt, mAttachedPlayer.ManaPercent);
            mExpBar.Update(gt, mAttachedPlayer.ExpPercent);
        }

        public override void Draw()
        {
            GraphicsSystem gfx = GameSystems.Graphics;
            //gfx.BeginSprites();
                gfx.DrawImage(mBackground, mPosition, Color.White);
                mHealthBar.Draw(mPosition + new Vector2(120, 14));
                mManaBar.Draw(mPosition+ new Vector2(120, 40));
                mExpBar.Draw(mPosition + new Vector2(15, 86));
                gfx.DrawText(mAttachedPlayer.Name, mPosition + new Vector2(20, 90), Color.White);
                gfx.DrawImage(mPicture, mPosition + new Vector2(43, 14), Color.White);
                gfx.DrawText("Defense: " + mAttachedPlayer.Defense, mPosition + new Vector2(20, 120), Color.Black);
            //gfx.EndSprites();
        }
        
    }
}
